// pages/children/children.js
const app=getApp()
var startX, endX;
var moveFlag = true;// 判断执行滑动事件

Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    content:"https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171cd.png",
    _id:1
  },
  touchStart: function (e) {
    startX = e.touches[0].pageX; // 获取触摸时的原点
    moveFlag = true;
  },
  // 触摸移动事件
  touchMove: function (e) {
    endX = e.touches[0].pageX; // 获取触摸时的原点

    if (moveFlag) {
      if (endX - startX > 50) {
        // console.log("move right");
        this.move2right();
        moveFlag = false;
      }
      if (startX - endX > 50) {
        // console.log("move left");
        this.move2left();
        moveFlag = false;
      }
    }

  },
  // 触摸结束事件
  touchEnd: function (e) {
    moveFlag = true; // 回复滑动事件
    
  },

  move2left() {
    var that = this;
    console.log(this.data.content)
    // console.log('向右滑动')
    if(this.data.content=='https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171cd.png'){

      that.setData({
        content: "https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171d6.png",
        _id:2
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171d6.png'){

      that.setData({
        content: "https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171bd.png",
        _id:3
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171bd.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171c0.png",
        _id:4
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171c0.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac1c2ab3f51d91e1966e.png",
        _id:5
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac1c2ab3f51d91e1966e.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b619.png",
        _id:6
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b619.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b61d.png",
        _id:7

      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b61d.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ad6c2ab3f51d91e20c83.png",
        _id:8
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ad6c2ab3f51d91e20c83.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b622.png",
        _id:9
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b622.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b62b.png",
        _id:10
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b62b.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b616.png",
        _id:11
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b616.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ad6c2ab3f51d91e20c7e.png",
        _id:12
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ad6c2ab3f51d91e20c7e.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171cd.png",
        _id:1
      });
    }
    
   
  },
  move2right() {
    var that = this;
    console.log(this.data.content)

    if(this.data.content=='https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171cd.png'){

      that.setData({
        content: "https://pic.imgdb.cn/item/6199ad6c2ab3f51d91e20c7e.png",
        _id:12
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171d6.png'){

      that.setData({
        content: "https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171cd.png",
        _id:1
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171bd.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171d6.png",
        _id:2
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171c0.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171bd.png",
        _id:3
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac1c2ab3f51d91e1966e.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ab9b2ab3f51d91e171c0.png",
        _id:4
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b619.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac1c2ab3f51d91e1966e.png",
        _id:5
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b61d.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b619.png",
        _id:6
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ad6c2ab3f51d91e20c83.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b61d.png",
        _id:7
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b622.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ad6c2ab3f51d91e20c83.png",
        _id:8
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b62b.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b622.png",
        _id:9
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b616.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b62b.png",
        _id:10
      });
    }
    else if(this.data.content=='https://pic.imgdb.cn/item/6199ad6c2ab3f51d91e20c7e.png'){
  
      that.setData({
        content: "https://pic.imgdb.cn/item/6199ac792ab3f51d91e1b616.png",
        _id:11
      });
    }

  },
  click:function(){
    console.log(this.data.content);
    wx.setStorageSync('children',this.data.content)
    let children=wx.getStorageSync('children');
    // console.log(children)
    if(children!=''){
      wx.showModal({
        title:'提示',
        content:'更换成功！'
      })
    }
  },
  onShow:function(){
    let style=wx.getStorageSync('style')
    if(style!=''){
      this.setData({
        contentStyle:wx.getStorageSync('style')
      })
    }else{
      this.setData({
        contentStyle:' https://pic.imgdb.cn/item/6199ad962ab3f51d91e21dd0.jpg'
      })
    }
  }
})